package ar.vc.trans;

public class GetMatRot
{
	public static float[][] getMatRot(float[][] Mi, float l)
	{
		float zc;
		
		if ( Mi[0][2] < Mi[2][2] )
			{ zc = Mi[0][2] + Math.abs(Mi[0][2] - Mi[2][2])/2.0f; }
		else
			{ zc = Mi[0][2] - Math.abs(Mi[0][2] - Mi[2][2])/2.0f; }
		
		float[][] A = {{  -l,   l,  zc,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f},
					   {   l,   l,  zc,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f},
					   {   l,  -l,  zc,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f},
					   {0.0f,0.0f,0.0f,  -l,   l,  zc,0.0f,0.0f,0.0f},
					   {0.0f,0.0f,0.0f,   l,   l,  zc,0.0f,0.0f,0.0f},
					   {0.0f,0.0f,0.0f,   l,  -l,  zc,0.0f,0.0f,0.0f},
					   {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,  -l,   l,  zc},
					   {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,   l,   l,  zc},
					   {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,   l,  -l,  zc}};
		
		float[] B = {Mi[0][0],
					 Mi[1][0],
					 Mi[2][0],
					 Mi[0][1],
					 Mi[1][1],
					 Mi[2][1],
					 Mi[0][2],
					 Mi[1][2],
					 Mi[2][2]};
		
		float[] X = GaussJordan.Solve(A, B, 9);
		
		float[][] R = {{X[0],X[1],X[2],0.0f},
					   {X[3],X[4],X[5],0.0f},
					   {X[6],X[7],X[8],0.0f},
					   {0.0f,0.0f,0.0f,1.0f}};
		
		return Inversa1.getInv(R, 4);
	}
}
